<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>

    <link rel="stylesheet" href="css/bootstrap.css">

    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.js"></script>
    <script src="js/bootstrap.bundle.js"></script>
</head>
<body>
<%
    if(session.getAttribute("username") == null){
        //表示没有登陆成功
        out.print("你尚未登录，三秒后跳转到登陆页面");
        response.setHeader("refresh","3;url=login.jsp");
    }else{


        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/book";

        Connection connection = DriverManager.getConnection(url,"root","root");

        String sql = "select * from user ";
        PreparedStatement ps = connection.prepareStatement(sql);



        ResultSet rs = ps.executeQuery();

        //ResultSet rs = stmt.executeQuery(sql);


%>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <h3 style="text-align: center">欢迎来到个人主页</h3>
            <table class="table table-striped">
                <thead>
                <th>ID</th>
                <th>用户名</th>
                <th>性别</th>
                <th>年龄</th>
                <th>操作</th>
                </thead>
                <tbody>
                <%
                        while (rs.next()){
                            out.print("<tr>");
                            out.print(
                                    "<td>"+rs.getString("id")
                                            +"</td><td>"+rs.getString("username")
                                            +"</td><td>"+rs.getString("gender")
                                            +"</td><td>"+rs.getString("age")
                                            +"</td>"
                                            +"<td><a href='delete.jsp?id="+rs.getString("id")+"'>删除</a>"
                                            +"&nbsp;<a href='edit.jsp?id="+rs.getString("id")+"'>修改</a>"
                                            +"/td"
                            );
                            out.print("</tr>");
                        }
                    }
                %>
                </tbody>
            </table>
        </div>
    </div>

</body>
</html>

